package com.yww.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yww.entity.Chat;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 雯雯yang
 * @since 2020-06-14
 */
public interface ChatMapper extends BaseMapper<Chat> {
    //添加动态内容
    Integer addMsgContent(Chat chat);

    //查询
    @Select("select chat.*,users.*,s.* from chat,users,student s WHERE chat.con_id=users.user_id AND chat.stu_id=s.stu_id AND users.user_id=#{userId}")
    List<Chat> getMessage(Integer userId);

    //查询
    @Select("select chat.*,users.*,s.* from chat,users,student s WHERE chat.con_id=users.user_id AND chat.stu_id=s.stu_id AND users.user_id=#{userId} and message_static=0 order by send_time limit 1")
    Chat getMessageRight(Integer userId);

    //消息状态改为已读
    @Update("update chat set message_static=1 where chat_id=#{chatId}")
    Integer updMessageStatic(Integer chatId);



}
